/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.inf.ufg.view.relatorio;

import br.inf.ufg.controller.CompraController;
import java.awt.BorderLayout;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.List;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author vinicius
 */
public class TelaRelatorioTotalVendas extends javax.swing.JFrame {

    private CompraController controll;
    
    private JScrollPane barraRolagem;
    private JTable tabela;
    private JPanel painel;
    private DefaultTableModel modelo = new DefaultTableModel();
    
    /**
     * Creates new form TelaRelatorioTotalVendas
     */    
    public TelaRelatorioTotalVendas() {
        try {
            controll = new CompraController();
            initComponents();
            criarTabela();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(TelaRelatorioTotalVendas.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(TelaRelatorioTotalVendas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    private void criarTabela() {        
        tabela = new JTable(modelo);
        modelo.addColumn("Evento");
        modelo.addColumn("Area");
	modelo.addColumn("Total Ingresos");
	modelo.addColumn("EmailTotal");
        loadData(modelo);
        barraRolagem = new JScrollPane(tabela);
        painel = new JPanel();
        painel.add(BorderLayout.CENTER, barraRolagem);
        getContentPane().add(painel);
    }
    
    private void loadData(DefaultTableModel modelo) {
        try {            
            List<String[]> results = controll.getResumoTotalVendas();
            for (String[] row : results) {
                modelo.addRow(new Object[]{row[0],row[1],row[2],row[3]});
            }
        } catch (SQLException ex) {
            Logger.getLogger(TelaRelatorioTotalVendas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 669, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 337, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
